package com.ruoyi.wechat.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.wechat.common.Constants;
import com.ruoyi.wechat.domain.AttachItem;
import com.ruoyi.wechat.mapper.AttachItemMapper;
import com.ruoyi.wechat.service.IAttachItemService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 商品大类附加服务
 * </p>
 *
 * @author YinHeng
 * @since 2024/4/22
 */
@Service
public class AttachItemServiceImpl extends ServiceImpl<AttachItemMapper, AttachItem> implements IAttachItemService {


    @Override
    public BigDecimal attachPrice(Integer type, Long itemId,List<Long> attachIds) {
        BigDecimal result = BigDecimal.ZERO;
        LambdaQueryWrapper<AttachItem> attachQuery = new LambdaQueryWrapper<>();
        attachQuery.eq(AttachItem::getEnable, Constants.Common.STATUS_1.getValue());
        attachQuery.eq(AttachItem::getType, type);
        attachQuery.eq(AttachItem::getItemId, itemId);
        attachQuery.in(AttachItem::getId,attachIds);
        List<AttachItem> list = this.list(attachQuery);
        if (ObjectUtils.isEmpty(list)) {
            return result;
        }
        for (AttachItem attach : list) {
            result = result.add(attach.getPrice());
        }
        return result;
    }
}
